<template>
  <div class="credit-score-card">
    <div class="score-display">
      <div class="score-number">{{ score || 600 }}</div>
      <div class="score-level">{{ getCreditLevel(score || 600) }}</div>
      <div class="score-progress">
        <el-progress 
          :percentage="getProgressPercentage(score || 600)" 
          :color="getProgressColor(score || 600)"
          :stroke-width="8"
        ></el-progress>
      </div>
    </div>
    <div class="score-info">
      <div class="info-item">
        <span class="label">信用等级：</span>
        <span class="value">{{ getCreditLevel(score || 600) }}</span>
      </div>
      <div class="info-item" v-if="lastUpdateTime">
        <span class="label">最近更新：</span>
        <span class="value">{{ parseTime(lastUpdateTime, '{y}-{m}-{d} {h}:{i}') }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CreditScoreCard",
  props: {
    score: {
      type: Number,
      default: 600
    },
    lastUpdateTime: {
      type: [String, Date],
      default: null
    }
  },
  methods: {
    /** 获取信用等级 */
    getCreditLevel(score) {
      if (score >= 800) return '优秀';
      if (score >= 700) return '良好';
      if (score >= 600) return '一般';
      if (score >= 500) return '较差';
      return '很差';
    },
    /** 获取进度百分比 */
    getProgressPercentage(score) {
      // 信用分范围：350-850，计算百分比
      const minScore = 350;
      const maxScore = 850;
      const percentage = ((score - minScore) / (maxScore - minScore)) * 100;
      return Math.max(0, Math.min(100, Math.round(percentage)));
    },
    /** 获取进度条颜色 */
    getProgressColor(score) {
      if (score >= 800) return '#67C23A'; // 绿色
      if (score >= 700) return '#409EFF'; // 蓝色
      if (score >= 600) return '#E6A23C'; // 橙色
      if (score >= 500) return '#F56C6C'; // 红色
      return '#909399'; // 灰色
    }
  }
};
</script>

<style scoped>
.credit-score-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  padding: 24px;
  color: white;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.credit-score-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.15);
}

.score-display {
  text-align: center;
  margin-bottom: 20px;
}

.score-number {
  font-size: 48px;
  font-weight: bold;
  margin-bottom: 8px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.score-level {
  font-size: 18px;
  margin-bottom: 16px;
  opacity: 0.9;
}

.score-progress {
  margin: 0 20px;
}

.score-info {
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  padding-top: 16px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
}

.info-item:last-child {
  margin-bottom: 0;
}

.label {
  opacity: 0.8;
}

.value {
  font-weight: 500;
}

/* 自定义进度条样式 */
:deep(.el-progress-bar__outer) {
  background-color: rgba(255, 255, 255, 0.2) !important;
}

:deep(.el-progress-bar__inner) {
  background: linear-gradient(90deg, #fff 0%, rgba(255, 255, 255, 0.8) 100%) !important;
}

:deep(.el-progress__text) {
  color: white !important;
  font-weight: bold;
}
</style> 